<template>
  <el-link type="primary" target="_blank" :href="getPdfUrl()">
    <el-tooltip
      class="item"
      effect="dark"
      :content="getPdfName()"
      placement="top-start"
    >
      <el-button size="mini" type="text">
        {{
          getPdfName() && getPdfName().length > 20 ? getPdfName().substring(0, 20) + '...' : getPdfName()
        }}
      </el-button>
    </el-tooltip>
  </el-link>
</template>

<script>
export default {
  name: 'readerFile',
  props: {
    fileUrl: {
      type: String,
      required: true
    }
  },
  methods: {
    getPdfName() {
      let files = this.fileUrl.split('/')
      let _names = files[files.length - 1]
      let fileName = _names
      if (_names && _names.indexOf('_') != -1) {
        let fileNames = _names.split('_')
        fileName = fileNames[fileNames.length - 1]
      }
      return '查看'
    },
    getPdfUrl() {
      let markParams = {
        'text': '三明市安保信息科技有限公司',
        'fontSize': '20',
        'color': 'rgba(128,128,128,0.6)',
        'rotate': '330',
        'Place': 'middleCenter',
        'Rule': 'all',
        'tiling': 'false',
        'fontName': 'SimSun',
        'distanceX': '10',
        'distanceY': '10'
      }
      let host = location.hostname
      if (host == '192.168.1.256') {
        host = host.replace('192.168.1.256', '192.168.1.241')
      }
      if (host == '192.168.1.246') {
        host = host.replace('192.168.1.246', '192.168.1.241')
      }
      if (host == '10.49.241.156') {
        host = host.replace('10.49.241.156', '10.49.241.151')
      }
      let origin = location.protocol + '//' + host
      let url = origin + ':8095/reader?file=' + this.fileUrl + '&markParams=' + encodeURIComponent(JSON.stringify(markParams))
      return url
    }
  }
}
</script>
